﻿⍝ Unicode and DotNet

⎕SE.FontObj←'APL385 Unicode' 22
⎕USING←''
text←'Compute average in APL: ' 'avg←{(+/⍵)÷⍴⍵}'
System.Text.Encoding.⎕nl -2
System.IO.File.WriteAllLines 'c:\temp\apl.txt' text System.Text.Encoding.UTF8
⎕USING←',system.dll'
notepad←System.Diagnostics.Process.Start⊂'c:\temp\apl.txt'
notepad
notepad.⎕NL -3
notepad.CloseMainWindow
System.IO.File.ReadAllLines ⊂'c:\temp\apl.txt'

⎕SE.SALT.Load 'C:\Docs\Dyalog\Demo\Unicode\UTF8File'
file←⎕NEW UTF8File 'c:\temp\apl.text'
file←⎕NEW UTF8File 'c:\temp\apl.txt' ⍝ Trace me!
file.Name
file.Text
file.Text←'The Ripple Shuffle:' '{⍵[⍒⍋(⍴⍵)⍴1 0]}'
)ED UTF8File
⎕SE.SALT.Explore 'C:\Docs\Dyalog\Demo\Unicode\UTF8File'
(⎕NEW UTF8File 'C:\Docs\Dyalog\Demo\Unicode\UTF8File.dyalog').Text
⎕EX 'UTF8File' ⍝ Remove Class from WS
(⎕SE.SALT.New 'C:\Docs\Dyalog\Demo\Unicode\UTF8File' 'c:\temp\apl.txt').Text
⎕NC 'UTF8File'

⍝ Now without .Net:
tn←'c:\temp\apl.txt' ⎕ntie 0
⎕←utf8text←⎕NREAD tn 80 (⎕nsize tn) 0
⎕←⎕UCS utf8text
⎕←text←'UTF-8' ⎕UCS ⎕UCS utf8text
⎕UCS 1⊃text
HEX ⎕UCS 1⊃text
1↓text
1↓text~⎕UCS 10
'UTF-8' ⎕UCS text
BOM←⎕UCS 65279 ⍝ FEFF = Byte Order Mark aka Zero width no-break space
(⎕UCS 'UTF-8' ⎕UCS BOM,text) ⎕NREPLACE tn 0
⎕NUNTIE tn